package com.think.oauth.user.security.token;

import java.util.LinkedHashMap;
import java.util.Map;

import javax.security.auth.login.CredentialException;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.common.exceptions.InvalidGrantException;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.OAuth2RequestFactory;
import org.springframework.security.oauth2.provider.TokenRequest;
import org.springframework.security.oauth2.provider.token.AbstractTokenGranter;
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;

public abstract class AbstractCustomTokenGranter extends AbstractTokenGranter {
	 protected AbstractCustomTokenGranter(AuthorizationServerTokenServices tokenServices, ClientDetailsService clientDetailsService, OAuth2RequestFactory requestFactory, String grantType) {
	        super(tokenServices, clientDetailsService, requestFactory, grantType);
	    }

	    @Override
	    protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, TokenRequest tokenRequest) {
	        OAuth2Authentication authentication = super.getOAuth2Authentication(client, tokenRequest);
//	        authentication.setDetails(details);
	        authentication.setAuthenticated(true);
	        return authentication;
	    }
	    
	    @Override
		public OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest) {
			// TODO Auto-generated method stub
			return super.grant(grantType, tokenRequest);
		}

		protected abstract UserDetails getUserDetails(Map<String, String> parameters) ;
}
